import re

# with open("D:\\BaiduNetdiskDownload\爬虫从入门到应用\\2022_06_08直播数据解析_正则\\素材\\匹配年.txt", 'r', encoding='utf-8') as f:
#     for line in f:      # 逐行匹配
#         year = re.search('([0-9]{1,2}年)', line)     # 匹配一次，至少匹配1个最多0-9中任意2个数字 + 年
#         try:
#             print(year.group())
#         except Exception as e:
#             pass
#
#     f.seek(0)       # 回到文件开头
#     year1 = re.findall('([0-9]{1,2}年)', f.read())   # 匹配所有，将文件内容转换为字符串
#     for i in year1:
#         print('in list' + ' ' + i)

# with open("D:\\BaiduNetdiskDownload\爬虫从入门到应用\\2022_06_08直播数据解析_正则\\素材\\匹配年.txt", 'r', encoding='utf-8') as f:
#     str = f.read()
# year_format = re.findall('\d{1,4}/\d{1,2}/\d{1,2}', str)
# for i in year_format:
#     print(i)

with open("D:\\BaiduNetdiskDownload\\爬虫从入门到应用\\2022_06_08直播数据解析_正则\\素材\\匹配邮箱手机号.txt", 'r', encoding='utf-8') as f:
    myStr = f.read()
phone_num = re.findall('[1]\d{10}', myStr)
for i in phone_num:
    print(i)

email_address = re.findall('\w{3,}@\w{3,}.com', myStr)      # \w等于字母 + 数字 + 下划线
for j in email_address:
    print(j)
